<template>
  <div class="">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <el-input v-model="filter.nickname" placeholder="姓名" size="small" clearable />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button size="small" @click="app.reset('filter')">清 空</el-button>
          <el-button type="primary" size="small" @click="getList">查 询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="app.loading" class="search-table" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="120px" prop="nickname" />
      <el-table-column label="部门" width="150px" prop="dep_name" />
      <el-table-column label="职位" width="150px" prop="pos_name" />
      <el-table-column label="联系电话" width="140px" prop="phone" />
      <el-table-column label="家庭住址" width="180px" prop="lived" />
      <el-table-column label="状态" align="center" width="80px" :formatter="formatter" />
      <el-table-column label="入职时间" align="center" width="110px" prop="induction_time" />
      <el-table-column label="申请理由" width="260px" prop="reason" />
      <!-- <el-table-column label="承诺人" width="120px" prop="promisor" />
      <el-table-column label="承诺日期" align="center" width="110px" prop="promise_date" /> -->
      <el-table-column label="申请日期" align="center" width="140px" prop="apply_time" />
      <el-table-column label="备注" min-width="260px" prop="remark" />
      <el-table-column label="操作" align="center" width="90px" fixed="right">
        <template slot-scope="{row}">
          <el-dropdown>
            <el-button type="primary" size="mini">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-if="row.state === 0" @click.native="handleDormitory(row)">入 住</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    <Dormitory ref="dormitory" :get-data="getList" :info="dialog" />
  </div>
</template>

<script>
import { dormitoryApplys } from '@/api/dormitory'
import Pagination from '@/components/Pagination'
import Dormitory from './components/dormitory-dialog'

export default {
  name: '',
  components: { Pagination, Dormitory },
  inject: ['app'],
  data() {
    return {
      list: [{name: '名称'}],
      dialog: {
        edit: {},
        title: '',
        type: ''
      },
      filter: {
        pageNumber: 10,
        pageCurrent: 1,
        pageAll: 1
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(e) {
      this.app.loading = true
      dormitoryApplys({
        ...this.filter,
        ...e
      }).then(response => {
        this.list = response.list
        this.filter = response.filter
        this.app.removeLoding()
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    formatter(e) {
      let state = e.state
      if(state === 0) {
        return '未入住'
      } else {
        return '已入住'
      }
    },
    handleDormitory(e) {
      this.dialog.title = '宿舍入住'
      this.dialog.type = 'add'
      this.app.dialogParam(this.dialog.edit, ['id', 'su_id', 'room_num', 'in_addr', 'in_time'], e)
      this.$refs['dormitory'].visible = true
    },
    outData(e) {

    }
  }
}
</script>
